#include "pub_ppm.h"

#ifdef WIN32
#include "windows.h"
#else
#include <signal.h>
#include <sys/types.h>
#include <unistd.h>
#endif

#define SLEEP_TIME 1


XercesInit g_cl_init;

bool g_b_broken=false;
string m_str_group;

//main
int main(int argc, char* argv[])
{ 
  try
  {
    std::cout<<"Connecting to database ..."<<flush;
    NPConnection cl_conn;
    cl_conn.open("PPM");
    
    while(!g_b_broken)
    {
      if(!cl_conn.isOpen())
      {
        std::cout<<"error connecting to database"<<endl;
        cl_conn.open("PPM");
      }
      
      OP_InterfaceManager op_interfaceManager(cl_conn);
	  std::cout<<"fuction started!"<<endl;
      op_interfaceManager.sendMessage();
	  std::cout<<"fuction end!"<<endl;
      
#ifdef WIN32
      Sleep(SLEEP_TIME*10);
#else
      sleep(SLEEP_TIME);
#endif  
    }
  }
  catch(CDbException* e)
  {
    std::cerr<<"CDbException: "<<e->getErrMsg()<<endl;
    delete e;
  }
  catch(UserException ue)
  {
    std::cerr<<"UserException: "<<ue.getMsg()<<endl;
  }
  catch(string &s)
  {
    std::cerr<<"exception: "<<s<<endl;
  }
  catch(...)
  {
    std::cerr<<"unknown exception... "<<endl;
  }
  return 1;
}
